<?php
session_start();
include('database.php');

$password=md5($_POST[password]);
$user_id = uniqid('U');

$query ="select * from users where username='$_POST[username]'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);

$query2 ="select * from users where email='$_POST[email]'";
$result2 = $mysqli->query($query2) or die($mysqli->error.__LINE__);

if($result->num_rows >= 1) {

header("Location: index.php?error=username#page_two");

}
else if($result2->num_rows >= 1){
header("Location: index.php?error=email#page_two");

}
else
{


if(isset($_POST[age])) //for developer
{
$query="insert into users (user_id,first_name,last_name,username,email,password,register_date,status,age,role) values ('$user_id','$_POST[first_name]','$_POST[last_name]','$_POST[username]','$_POST[email]','$password',now(),'inactive','$_POST[age]','developer')";
mysqli_query($mysqli,$query);
}else //for standart user
{
$query="insert into users (user_id,first_name,last_name,username,email,password,register_date,status,age,role) values ('$user_id','$_POST[first_name]','$_POST[last_name]','$_POST[username]','$_POST[email]','$password',now(),'inactive',0,'user')";
mysqli_query($mysqli,$query);
}
$_SESSION[user_id]=$user_id;
$_SESSION[register]="success";

header("Location: email.php?target=registration&email=$_POST[email]");
}




?>

